home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / Snippets / Toolbox / readLocation / readLocation.p < prev    next >
Encoding:
Text File  |  1992-07-15  |  1.6 KB  |  64 lines  |  [TEXT/MPS ]

  1.   readLocation
  2.  
  3.   retrieves the map settings for longitude and latitude and
  4.   the time offset from GMT
  5.   
  6.   for more information, see Worldwide Development: Guide to System Software
  7.   
  8.   Greg Robbins 12/91
  9.  
  10. }
  11.  
  12. { requires SIOW for WriteLn }
  13.  
  14. PROGRAM location;
  15.  
  16. USES Types, Script, FixMath;
  17.  
  18. VAR
  19.     myMachineLocation: MachineLocation;
  20.     latExt, longExt: EXTENDED;
  21.     latDeg, latMin, longDeg, longMin: LONGINT;
  22.     theGmtDelta, hours, minutes, seconds: LONGINT;
  23.     
  24.     FUNCTION GetGmtDelta(myLocation: MachineLocation): LONGINT;
  25.     VAR
  26.         internalGmtDelta: LONGINT;
  27.     BEGIN
  28.         { change 3-byte integer to LONGINT }
  29.         internalGmtDelta := BAND(myLocation.gmtDelta,$00FFFFFF);
  30.         IF BTST(internalGmtDelta,23) THEN { sign extend }
  31.             internalGmtDelta := BOR(internalGmtDelta,$FF000000);
  32.         GetGmtDelta := internalGmtDelta;
  33.     END;
  34.  
  35. BEGIN
  36.     ReadLocation(myMachineLocation);
  37.     
  38.     { convert location to extended fraction }
  39.     latExt := Frac2X(myMachineLocation.latitude);
  40.     longExt := Frac2X(myMachineLocation.longitude);
  41.     
  42.     { convert location to degrees-minutes }
  43.     latDeg := TRUNC(latExt * 90);
  44.     latMin := TRUNC((latExt * 90 - latDeg) * 60);
  45.  
  46.     longDeg := TRUNC(longExt * 90);
  47.     longMin := TRUNC((longExt * 90 - longDeg) * 60);
  48.     
  49.     { find time zone w.r.t. GMT }
  50.     theGmtDelta := GetGmtDelta(myMachineLocation);
  51.     hours := theGmtDelta DIV 3600;
  52.     minutes := (theGmtDelta MOD 3600) DIV 60;
  53.     seconds := theGmtDelta MOD 60;
  54.     
  55.     { negative values indicate South or West }
  56.     WriteLn('latitude:  ', latDeg, CHR($A1), latMin, CHR($27));
  57.     WriteLn('longitude: ', longDeg, CHR($A1), longMin, CHR($27));
  58.     
  59.     { negative values indicate West }
  60.     WriteLn('time from GMT: ', hours:3, ' h ', minutes:3, ' m ', 
  61.         seconds:2, ' s');
  62. END.
  63.